#region Copyright Notice
// 
// 
//  
//  Copyright (c) 2009-2011 Anindya Chatterjee
//  
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//  
//      http://www.apache.org/licenses/LICENSE-2.0
//  
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
// 
// 
#endregion
using System;

namespace AbstractClass.Extensions
{
    /// <summary>
    /// Provides a set of extension methods for numeric types.
    /// </summary>
    public static class MathExtensions
    {
        /// <summary>
        ///   Calculates <paramref name = "baseNumber" /> to the power <paramref name = "exponent" />.
        /// </summary>
        /// <param name = "baseNumber">The base number.</param>
        /// <param name = "exponent">The exponent.</param>
        /// <returns>
        /// A <see cref="double"/> value which is equal to <paramref name = "baseNumber" /> to the power <paramref name = "exponent" />.
        /// </returns>
        public static double ToThePower(this int baseNumber, double exponent)
        {
            return Math.Pow(baseNumber, exponent);
        }

        /// <summary>
        ///   Calculates (e * <paramref name = "baseNumber" />) to the power <paramref name = "exponent" />.
        /// </summary>
        /// <param name = "baseNumber">The base number.</param>
        /// <param name = "exponent">The exponent.</param>
        /// <returns>
        /// A <see cref="double"/> value which is equal to (e * <paramref name = "baseNumber" />) to the power <paramref name = "exponent" />.
        /// </returns>
        public static double EToThePower(this int baseNumber, double exponent)
        {
            return Math.E.ToThePower(exponent) * baseNumber;
        }


        /// <summary>
        ///   Calculates <paramref name = "baseNumber" /> to the power <paramref name = "exponent" />.
        /// </summary>
        /// <param name = "baseNumber">The base number.</param>
        /// <param name = "exponent">The exponent.</param>
        /// <returns>
        /// A <see cref="double"/> value which is equal to <paramref name = "baseNumber" /> to the power <paramref name = "exponent" />.
        /// </returns>
        public static double ToThePower(this long baseNumber, double exponent)
        {
            return Math.Pow(baseNumber, exponent);
        }

        /// <summary>
        ///   Calculates (e * <paramref name = "baseNumber" />) to the power <paramref name = "exponent" />.
        /// </summary>
        /// <param name = "baseNumber">The base number.</param>
        /// <param name = "exponent">The exponent.</param>
        /// <returns>
        /// A <see cref="double"/> value which is equal to (e * <paramref name = "baseNumber" />) to the power <paramref name = "exponent" />.
        /// </returns>
        public static double EToThePower(this long baseNumber, double exponent)
        {
            return Math.E.ToThePower(exponent) * baseNumber;
        }

        /// <summary>
        ///   Calculates <paramref name = "baseNumber" /> to the power <paramref name = "exponent" />.
        /// </summary>
        /// <param name = "baseNumber">The base number.</param>
        /// <param name = "exponent">The exponent.</param>
        /// <returns>
        /// A <see cref="double"/> value which is equal to <paramref name = "baseNumber" /> to the power <paramref name = "exponent" />.
        /// </returns>
        public static double ToThePower(this float baseNumber, double exponent)
        {
            return Math.Pow(baseNumber, exponent);
        }

        /// <summary>
        ///   Calculates (e * <paramref name = "baseNumber" />) to the power <paramref name = "exponent" />.
        /// </summary>
        /// <param name = "baseNumber">The base number.</param>
        /// <param name = "exponent">The exponent.</param>
        /// <returns>
        /// A <see cref="double"/> value which is equal to (e * <paramref name = "baseNumber" />) to the power <paramref name = "exponent" />.
        /// </returns>
        public static double EToThePower(this float baseNumber, double exponent)
        {
            return Math.E.ToThePower(exponent) * baseNumber;
        }

        /// <summary>
        ///   Calculates <paramref name = "baseNumber" /> to the power <paramref name = "exponent" />.
        /// </summary>
        /// <param name = "baseNumber">The base number.</param>
        /// <param name = "exponent">The exponent.</param>
        /// <returns>
        /// A <see cref="double"/> value which is equal to <paramref name = "baseNumber" /> to the power <paramref name = "exponent" />.
        /// </returns>
        public static double ToThePower(this double baseNumber, double exponent)
        {
            return Math.Pow(baseNumber, exponent);
        }

        /// <summary>
        ///   Calculates (e * <paramref name = "baseNumber" />) to the power <paramref name = "exponent" />.
        /// </summary>
        /// <param name = "baseNumber">The base number.</param>
        /// <param name = "exponent">The exponent.</param>
        /// <returns>
        /// A <see cref="double"/> value which is equal to (e * <paramref name = "baseNumber" />) to the power <paramref name = "exponent" />.
        /// </returns>
        public static double EToThePower(this double baseNumber, double exponent)
        {
            return Math.E.ToThePower(exponent) * baseNumber;
        }

        /// <summary>
        ///   Inverses the specified number.
        /// </summary>
        /// <param name = "number">The number to inverse.</param>
        /// <returns>
        /// A <see cref="double"/> value which is equal to inverse of <paramref name="number"/>.
        /// </returns>
        public static double Inverse(this int number)
        {
            return number.ToThePower(-1);
        }

        /// <summary>
        ///   Inverses the specified number.
        /// </summary>
        /// <param name = "number">The number to inverse.</param>
        /// <returns>
        /// A <see cref="double"/> value which is equal to inverse of <paramref name="number"/>.
        /// </returns>
        public static double Inverse(this long number)
        {
            return number.ToThePower(-1);
        }

        /// <summary>
        ///   Inverses the specified number.
        /// </summary>
        /// <param name = "number">The number to inverse.</param>
        /// <returns>
        /// A <see cref="double"/> value which is equal to inverse of <paramref name="number"/>.
        /// </returns>
        public static double Inverse(this float number)
        {
            return number.ToThePower(-1);
        }

        /// <summary>
        ///   Inverses the specified number.
        /// </summary>
        /// <param name = "number">The number to inverse.</param>
        /// <returns>
        /// A <see cref="double"/> value which is equal to inverse of <paramref name="number"/>.
        /// </returns>
        public static double Inverse(this double number)
        {
            return number.ToThePower(-1);
        }

        /// <summary>
        ///  Determines whether a number is not within a specified range.
        /// </summary>
        /// <param name = "number">The number.</param>
        /// <param name = "min">The minimum range.</param>
        /// <param name = "max">The maximum range.</param>
        /// <returns>
        /// <c>true</c> if <paramref name = "number" /> not in the range of <paramref name = "min" /> and <paramref name = "max" />; otherwise, <c>false</c>.
        /// </returns>
        public static bool NotInRange(this double number, double min, double max)
        {
            return !WithInRange(number, min, max);
        }

        /// <summary>
        ///   Determines whether a number is within a specified range.
        /// </summary>
        /// <param name = "number">The number.</param>
        /// <param name = "min">The minimum range.</param>
        /// <param name = "max">The maximum range.</param>
        /// <returns>
        /// <c>false</c> if <paramref name = "number" /> not in the range of <paramref name = "min" /> and <paramref name = "max" />; otherwise, <c>true</c>.
        /// </returns>
        public static bool WithInRange(this double number, double min, double max)
        {
            return (number > min) && (number < max);
        }

        /// <summary>
        ///   Calculates <paramref name = "baseNumber" /> to the power <paramref name = "index" />.
        /// </summary>
        /// <param name = "baseNumber">The base number.</param>
        /// <param name = "index">The index.</param>
        /// <returns>
        /// A <see cref="ComplexNumber"/>which is equal to <paramref name = "baseNumber" /> to the power <paramref name = "index" />.
        /// </returns>
        public static ComplexNumber ToThePower(this double baseNumber, ComplexNumber index)
        {
            return QMath.Exp(index * Math.Log(baseNumber));
        }
    }
}